﻿using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKRevitBase.WinForm;

namespace YJKArchiFormat
{
	[Regeneration(RegenerationOption.Manual)]
	[Transaction(TransactionMode.Manual)]
	public class CmdStandardRoom : YJKCommandManual
	{
		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		protected override Result YJKExcute(ExternalCommandData cmdData, ref string message, ElementSet elements)
		{
			if (cmdData.Application.ActiveUIDocument.Document.PathName == "")
			{
				MessageBox.Show("请先保存新建项目后再运行此功能", "盈建科提示");
				return Autodesk.Revit.UI.Result.Failed;
			}
			try
			{
				Process currentProcess = Process.GetCurrentProcess();
				if (currentProcess != null)
				{
                    WindowHandle owner = new WindowHandle(currentProcess.MainWindowHandle);
					try
					{
						while (DlgMain.GetInstance(cmdData.Application).ShowDialog(owner) == DialogResult.OK)
						{
						}
						goto IL_77;
					}
					catch (Exception ex)
					{
						MessageBox.Show(ex.Message);
						goto IL_77;
					}
				}
				MessageBox.Show("未能得到当前Revit进程！");
				IL_77:;
			}
			catch (Exception ex2)
			{
				MessageBox.Show(ex2.Message);
			}
			return base.YJKExcute(cmdData, ref message, elements);
		}
	}
}
